package com.cheems.springbootinit.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cheems.springbootinit.model.dto.search.SearchRequest;
import com.cheems.springbootinit.model.entity.Chapter;
import com.cheems.springbootinit.model.entity.Picture;
import com.cheems.springbootinit.model.vo.SearchVO;
import com.cheems.springbootinit.service.ChapterService;
import com.cheems.springbootinit.service.PictureService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 帖子接口
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
@RestController
@RequestMapping("/picture")
@Slf4j
public class SearchController {

    @Resource
    private PictureService pictureService;

    @Resource
    private ChapterService chapterService;
    /**
     * 搜索图片接口
     * @return
     */
    @PostMapping("/all")
    public SearchVO searchAll(SearchRequest searchRequest){
        String searchText = searchRequest.getSearchText();
        Page<Picture> picturePage = pictureService.searchPicture(searchText, 1, 10);
        LambdaQueryWrapper<Chapter> chapterWrpper = new LambdaQueryWrapper<>();
        chapterWrpper.like(Chapter::getTitle,searchText);
        List<Chapter> list = chapterService.list(chapterWrpper);
        SearchVO searchVO = new SearchVO();
        searchVO.setChapterList(list);
        //searchVO.setPictureList((List<Picture>) picturePage);
        return searchVO;
    }

}
